package org.zecontech.extraplus.client;

import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SaplingBlock;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
import org.zecontech.extraplus.ExtraPlus;
import org.zecontech.extraplus.block.HerbBlock;
import org.zecontech.extraplus.client.renderer.KelongRenderer;
import org.zecontech.extraplus.client.renderer.NailongRenderer;
import org.zecontech.extraplus.entity.Kelong;
import org.zecontech.extraplus.entity.Nailong;
import org.zecontech.extraplus.init.ModBlocks;
import org.zecontech.extraplus.init.ModEntities;

/**
 * 模组客户端入口点
 */
@EventBusSubscriber(modid = ExtraPlus.MOD_ID, value = Dist.CLIENT)
public class ExtraPlusClient {

    /**
     * 注册实体属性
     * @param event 属性事件
     */
    @SubscribeEvent
    public static void registerEntityAttributes(EntityAttributeCreationEvent event) {
        event.put(ModEntities.KELONG.get(), Kelong.createAttributes().build());
        event.put(ModEntities.NAILONG.get(), Nailong.createAttributes().build());
    }

    /**
     * 注册模组实体渲染
     * @param event 渲染事件
     */
    @SubscribeEvent
    public static void registerEntityRenderer(EntityRenderersEvent.RegisterRenderers event) {
        event.registerEntityRenderer(ModEntities.KELONG.get(),
                KelongRenderer::new);
        event.registerEntityRenderer(ModEntities.NAILONG.get(),
                NailongRenderer::new);
    }

    /**
     * 注册方块客户端渲染
     * @param event 渲染事件
     */
    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public static void registerBlockClients(FMLClientSetupEvent event) {
        ModBlocks.BLOCKS.getEntries().forEach(block -> {
            if (block.get() instanceof HerbBlock
                    || block.get() instanceof FlowerPotBlock
                    || block.get() instanceof CropBlock
                    || block.get() instanceof LeavesBlock
                    || block.get() instanceof SaplingBlock) {
                ItemBlockRenderTypes.setRenderLayer(block.get(), ChunkSectionLayer.CUTOUT);
            }
        });
    }
}
